﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Game
{
    namespace CharacterAction
    {
        public abstract class Base
        {
            public abstract void Apply(Character Controller);
        }

        public class ActionGroup : List<Base>
        {
        }

        public class Moving : Base
        {
            protected float mMoveSpeed = 8f; //0.05f;
            protected float mJumpSpeed = 12f;
            protected float mTurnSpeed = 8f; //5f; //0.02f;
            
            public enum State
            {
                Sprint,
                Forward,
                Backward,
                TurnLeft,
                TurnRight,
                Jump,
            }

            private Set<State> StateSet = new Set<State>();

            public void Move(bool turn, State state)
            {
                if (turn)
                {
                    StateSet.Include(state);
                }
                else
                {
                    StateSet.Exclude(state);
                }
            }

            public override void Apply(Character Controller)
            {
                //reset parameters
                float moveSpeed = mMoveSpeed;

                if (StateSet.IsEmpty())
                {
                    return; //is Idle
                }

                foreach (State state in StateSet)
                {
                    switch (state)
                    {
                        //Sprint
                        case State.Sprint:
                            moveSpeed = mMoveSpeed * 2;
                            break;
                        //TurnLeft
                        case State.TurnLeft:
                            //Controller.Body.Rotate(IDK.Quaternion.Rotate(IDK.Vector3.UpY, new IDK.Radian(new IDK.Degree(-10))));
                            Controller.Body.AddForce(new IDK.Vector3(mTurnSpeed, 0, 0));
                            // IDK.Vector2 tl = new IDK.Vector2(-mTurnSpeed, 0.0f);
                            // Body.Rotate(tl); 
                            break;

                        //TurnRight
                        case State.TurnRight:
                            //Controller.Body.Rotate(IDK.Quaternion.Rotate(IDK.Vector3.UpY, new IDK.Radian(new IDK.Degree(10))));
                            Controller.Body.AddForce(new IDK.Vector3(-mTurnSpeed, 0, 0));
                            // IDK.Vector2 tr = new IDK.Vector2(mTurnSpeed, 0.0f);
                            // Body.Rotate(tr); 
                            break;

                        //Forward
                        case State.Forward:
                            Controller.Body.AddForce(new IDK.Vector3(0, 0, moveSpeed));
                            break;

                        //Backward
                        case State.Backward:
                            Controller.Body.AddForce(new IDK.Vector3(0, 0, -moveSpeed));
                            break;

                        //Jump
                        case State.Jump:
                            Controller.Body.AddImpulse(new IDK.Vector3(0, mJumpSpeed, 0));
                            StateSet.Exclude(State.Jump);
                            break;
                    }
                }
            }
        }

        public class LookAtPoint : Base
        {
            protected IDK.Vector3 DesiredLook = IDK.Vector3.Zero;

            public override void Apply(Character Controller)
            {
                Controller.Body.LookAtPoint(DesiredLook);
            }
        }
    }
}
